from pathlib import Path

#第一问
def py(src=""):
    p=Path(src)
    lf=[]
    def pyfile(p):
        nonlocal lf
        for x in p.iterdir():
            if x.is_dir():
                pyfile(x)
            elif x.is_file():
                if x.suffix==".py":
                    lf.append(str(x))
    pyfile(p)
    return(lf)


#第二问
from pathlib import Path

class Py():
    def __init__(self,src):
        self.p=Path(src)
        self.fl=[self.p.iterdir()]
        self.i=0
    
    def __iter__(self):
        return self
    
    def __next__(self):
        while self.i<len(self.fl):
            self.x = self.fl[self.i]
            try:
                pp = next(self.x)
                while pp.suffix!=".py":
                    if pp.is_dir():
                        self.fl.append(pp.iterdir())
                    pp = next(self.x)
                return pp
            except StopIteration:
                self.i += 1
        
        raise StopIteration